<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="../init_include.jsp" %>

<%
	Integer catId;
	int totalpages,pageid=0;
	int pagerows=Page.getPageRows();
	int totalUsers=0;
	int titleMaxLen=20;
  String ordermode="desc";
  String orderfield="id";
  
	int check_rst=Permission.accept(dbi,session,request,"sysop","tree","catid","000000010"); 
	if (check_rst!=Permission.CHECK_RST_SUCCESS) {
		dbi.closeAll();
		if (check_rst==Permission.CHECK_RST_DENY)
			response.sendRedirect("../deny.html");
		else 
			response.sendRedirect("../index.jsp?DestUrl="+request.getContextPath()+"?"+request.getQueryString());
		return;		
	}

	Sysop sysop=(Sysop)session.getAttribute("sysop");	
	int userid = sysop.getId();
	try {
		if (request.getParameter("id")!=null)
			userid=Integer.parseInt(request.getParameter("id"));
	}	catch(NumberFormatException e) {
		return ;
	}	
		

	if(request.getParameter("ordermode")!=null)
		ordermode=request.getParameter("ordermode");	
	if(request.getParameter("orderfield")!=null)
		orderfield=request.getParameter("orderfield");		

	String whereClause="";
	if(request.getParameter("whereClause")!=null)
		whereClause=request.getParameter("whereClause");	
	whereClause=whereClause.trim();

	String a=request.getParameter("catid");
	String str="";
	try {
		catId=Integer.valueOf(a);		
	}	catch(NumberFormatException e) {
		out.println(e+"catId");
		return;
	}
	
	try {
		if (request.getParameter("pageid")!=null)
			pageid=Integer.parseInt(request.getParameter("pageid"));
		else
			pageid=1;
	}	catch(NumberFormatException e) {
		out.println(e+"pageid");
		pageid=1;
	}	
	
	try {
		if (request.getParameter("pagerows")!=null)
			pagerows=Integer.parseInt(request.getParameter("pagerows"));
	} catch(NumberFormatException e) {
		out.println(e+"pagerows");
	}	

	totalUsers=Sysop.getUserNum(dbi,whereClause);
	totalpages = (int)Math.ceil((double)totalUsers/pagerows);
	if(pageid>totalpages)
		pageid=totalpages;
	if(pageid<=1)
		pageid=1;
%>	
<html>
<head>
<title><%=Language.getNameByCode("sys.sysop.manage","User Manage")%></title>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Language.getHTMLLanguageStr()%>">
<link rel="stylesheet" href="../css.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../script/Ion_Show.js"></SCRIPT>
<script language="javascript">
<!--
	function Ion_Del()
	{
		deleteIon('vmsSelectFrame.jsp','../ums/sysop_delete.jsp','<%=Language.getNameByCode("sys.sysop","user")%>');
	}

	function Ion_Edit()
	{
		editIon('vmsSelectFrame.jsp','../ums/sysop_dj.jsp','<%=Language.getNameByCode("sys.sysop","user")%>');
	}

	function Ion_View()
	{
		editIon('vmsSelectFrame.jsp','../ums/sysop_view.jsp','<%=Language.getNameByCode("sys.sysop","user")%>');
	}

	function Ion_GotoLayer()
	{
		location.href="userManager.jsp?catid="+window.formIon.catid.value;
	}
	
	function Ion_Add()
	{
		add_Ion('vmsSelectFrame.jsp','../ums/sysop_dj.jsp','userid');
	}

	function Ion_Search()
	{
		add_Ion('vmsSelectFrame.jsp','../ums/sysop_search.jsp','userid',"search_user");
	}

-->
</script>
</head>

<body bgColor=#d6d3ce leftMargin=0 style="BORDER-BOTTOM: 0px outset; BORDER-LEFT: 0px outset; BORDER-RIGHT: 0px outset; BORDER-TOP: 0px outset" topMargin=0>

<FORM name="formIon" method="post" action="?">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
  <tr>
    <td class="nagivation" colspan="2"><%=Language.getNameByCode("sys.CurrentPos","Current Position")%>
    <% 
    Vector vcpath=Category.getLadder(session,"tree",(catId.intValue()));
		out.print(Category.getFullPath(vcpath));
		
	UserTreeManager utm = new UserTreeManager();
	utm.setSqlNode( "select id,name,parentid,layer from sysop" );
	Vector aavc = utm.getAllAncestors( dbi, userid );
	boolean href = false;
	for( int i = 0; i < aavc.size(); i++ ){
		UserTreeNode node = (UserTreeNode)aavc.get(i);
		if( node.getParentId() == sysop.getId() || node.getId() == sysop.getId() )
			href= true;
		if( href ){
%>
		-&gt; <a href="userManager.jsp?catid=<%=catId%>&id=<%=node.getId()%>"><%=node.getName()%></a>
<%
		}
		else{
%>
		-&gt; <%=node.getName()%>
<%		}
	}
%>
		
		</td>
  </tr>
 	<tr>
   	<td align="left">
   		<%=Language.getNameByCode("sys.sysop.userlist","Users List")%><%=PageStr.getPageHead(totalUsers,pageid,pagerows,totalpages)%>
   		&nbsp;&nbsp;<% if(whereClause!=null && whereClause.length()>0) {%><a href="javascript:stopSearch();"><%=Language.getNameByCode("sys.clearsearch","Clear Search Condition")%></a><%}%>
    </td>
    <td align=right>
			<%=PageStr.PageForm(pageid,totalpages)%><input type="submit" name="Submit" value="go" style="width:0">
    </td>
  </tr>
</table>

	<TABLE border=0 cellPadding=0 cellSpacing=1 height="100%" width="100%">
		<input type="hidden" name="catid" value="<%=catId%>">
		<input type="hidden" name="id" value="<%=userid%>">
		<input type="hidden" name="whereClause" value="<%=whereClause%>">
		<INPUT name="objid" type="hidden">
		<INPUT name="objtext" type="hidden">
		<INPUT name="objflag" type="hidden">
		<INPUT name="actionurl" type="hidden">
		<input type="hidden" name="orderfield" value="<%=orderfield%>">
		<input type="hidden" name="ordermode" value="<%=ordermode%>">
  	<TR>
    <TD>
<%    
   Table table=new Table();
   table.setSortMode(ordermode);
   table.setSortField(orderfield);
   table.setSelectionMode("multiple");

   table.addColumn("no","id",0,"center","left","number");
   table.addColumn(Language.getNameByCode("sys.sysop.id","ID"),"ID",30,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.sysop.name","Name"),"name",80,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.sysop.fullname","FullName"),"fullname",100,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.sysop.status","Status"),"status",60,"center","center","text");
   table.addColumn(Language.getNameByCode("sys.sysop.depart","Deaprtment"),"departid",80,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.sysop.email","Email"),"email",70,"center","right","text");
   table.addColumn(Language.getNameByCode("sys.sysop.logincount","Login Counts"),"logincount",80,"center","right","number");
   table.addColumn(Language.getNameByCode("sys.sysop.lastlogin","Last Date"),"lastlogin",80,"center","right","number");
   table.addColumn(Language.getNameByCode("sys.sysop.usermanage","user manage privilege"),"rightflag",0,"center","right","text");

  Vector vc=Sysop.getAllSysopsWithUser(dbi,whereClause,pageid,pagerows,orderfield,ordermode);
  String statusstr[]=StaticDim.getUserStatus();
  ArrayList rowsList=new ArrayList();
	for (int i=0;i<vc.size();i++){	
		Sysop user=(Sysop)vc.get(i);
    String rowData=user.getId()+"|"+user.getId()+"|"+(user.getRightFlag()==1?">>":"&nbsp;&nbsp;")+""+user.getName()+"|"+user.getFullName()+"|"+statusstr[user.getStatus()];
    if(user.getStatus()==1 && user.getExpire()!=null)
    	rowData+=user.getExpire();
    rowData+="|"+user.getDepartName()+"| "+user.getEmail()+"|"+user.getLoginCount()+"|"+user.getLastLogin()+"|"+user.getRightFlag();
		rowsList.add(rowData);
	}
  ArrayList menuList=new ArrayList();
  TableMenu tm=null;
  tm=new TableMenu(Language.getNameByCode("sys.sysop.Edit","Edit Selected User"),"javascript:javascript:Ion_Edit();",false);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.Add","Add New User"),"javascript:javascript:Ion_Add();",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.SeeChild","View Sub-User"),"javascript:changeIon('userManager.jsp','"+Language.getNameByCode("sys.sysop","User")+"',9);",false);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.SeeClass","View UserClass"),"javascript:editIon('vmsSelectFrame.jsp','user_class_list.jsp','"+Language.getNameByCode("sys.sysop","User")+"');",false);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.Move","Move User To Sub"),"javascript:check('vmsSelectFrame.jsp','selectSysop.jsp','"+Language.getNameByCode("sys.sysop","User")+"');",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.changename","Change Name To ..."),"javascript:editIon('vmsSelectFrame.jsp','Sysop_changeName.jsp','"+Language.getNameByCode("sys.sysop","User")+"');",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.View")+Language.getNameByCode("sys.sysop","User"),"javascript:Ion_View();",true);
  menuList.add(tm);
  if(SmsEnv.isSuperUser(sysop.getName())) {
	  tm=new TableMenu(Language.getNameByCode("sys.sysop.ViewLayer","View Sysop"),"javascript:Ion_GotoLayer();",true);
  	menuList.add(tm);
  }
  tm=new TableMenu(Language.getNameByCode("sys.Head.Refresh","Refresh"),"javascript:self.location.reload();",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.Delete","Delete Selected User"),"javascript:Ion_Del();",true);
  menuList.add(tm);
  tm=new TableMenu(Language.getNameByCode("sys.sysop.search","Search User"),"javascript:Ion_Search();",false);
  menuList.add(tm);

  table.setTableMenu(menuList);
  table.setRowsList(rowsList);
  TableDB tdb=new TableDB();
  out.print(tdb.draw(table));
%>  
	  </TD>
 	</TR>
 	</FORM>
	</TABLE>
</body>
</html>
<%@ include file="../init_free.jsp" %>